package cn.wangqi.personal.service;

import cn.wangqi.personal.dao.BlogUserDao;
import cn.wangqi.personal.domain.BlogUser;
import cn.wangqi.personal.password.PasswordHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by admin on 2017/9/23.
 */
@Service
public class BlogUserService implements IBlogUserService{

    private Logger logger = Logger.getLogger(BlogUserService.class);

    @Resource
    private BlogUserDao blogUserDao;

    private PasswordHelper passwordHelper = new PasswordHelper();

    @Override
    public BlogUser findBlogUserByUserName(String userName) {
        return blogUserDao.findBlogUserByUserName(userName);
    }


    @Override
    public void createUser(BlogUser blogUser) {
        //加密密码
        passwordHelper.encryptPassword(blogUser);
        blogUserDao.saveBlogUser(blogUser);
    }



    @Override
    public void changePassword(Integer userId, String newPassword) {
        BlogUser blogUser = blogUserDao.findBlogUserById(userId);
        blogUser.setPassword(newPassword);
        passwordHelper.encryptPassword(blogUser);
        blogUserDao.updateBlogUser(blogUser);
    }
}

